﻿using Rhino;
using Rhino.Commands;
using System;
using YangTools.Realization;

namespace YangTools
{
    public class BlockSubObjectsAddCommand : Command
    {
        static BlockSubObjectsAddCommand _instance;
        public BlockSubObjectsAddCommand()
        {
            _instance = this;
        }

        public static BlockSubObjectsAddCommand Instance
        {
            get { return _instance; }
        }

        public override string EnglishName
        {
            get { return "AddToBlock"; }
        }

        /// <summary>
        /// 将物体添加到图块
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetOption();
            var t = new Rhino.Input.Custom.OptionToggle(true, "否", "是");
            go.AddOptionToggle("保留", ref t);
            go.AcceptNothing(true);
            go.SetCommandPrompt("是否保留添加的物体");
            var r = go.Get();

            bool keepAddObjects = true;
            if (r == Rhino.Input.GetResult.Option) keepAddObjects = t.CurrentValue;

            var atb = new BlockSubObjects();
            atb.AddToBlock(keepAddObjects);
            return Result.Success;
        }
    }
}